package com.qiudaozhang.service.impl;

import com.qiudaozhang.dto.ResponseCode;
import com.qiudaozhang.mapper.GoodsInfoMapper;
import com.qiudaozhang.model.GoodsInfo;
import com.qiudaozhang.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.Date;
import java.util.List;
@Service
public class GoodsServiceImpl implements GoodsService{
    @Autowired
    private GoodsInfoMapper goodsMapper;
    @Override
    public ResponseCode query(String goodsName) {
        ResponseCode code = new ResponseCode();
        List<GoodsInfo> list=goodsMapper.query(goodsName);
        code.setData(list);
        code.setCode(0);
        return code;
    }

    @Override
    public void add(GoodsInfo goodsInfo) {
        goodsInfo.setCreatetime(new Date());
        goodsInfo.setLastupdatetime(new Date());
        goodsMapper.add(goodsInfo);
    }

    @Override
    public GoodsInfo queryById(Long id) {
        return goodsMapper.queryById(id);
    }

    @Override
    public void modifyById(GoodsInfo goodsInfo) {
        goodsInfo.setLastupdatetime(new Date());
        goodsMapper.modifyById(goodsInfo);
    }

    @Override
    public ResponseCode delById(Long id) {
        ResponseCode code = new ResponseCode();
        Integer row = goodsMapper.delById(id);
        if(row>0){
            code.setCode(ResponseCode.SUCCESS);
            code.setMsg("删除成功！！");
        }else{
            code.setCode(ResponseCode.FAIL);
            code.setMsg("删除失败！！");
        }
        return code;
    }
}
